package cmd

import (
	"context"
	"donkey-admin/internal/consts"
	"donkey-admin/internal/controller/apis"
	"donkey-admin/internal/controller/healthy"
	"donkey-admin/internal/controller/login"
	"donkey-admin/internal/controller/menu"
	"donkey-admin/internal/controller/operation_log"
	"donkey-admin/internal/controller/role"
	"donkey-admin/internal/controller/task"
	"donkey-admin/internal/controller/taskLog"
	"donkey-admin/internal/controller/user"
	"donkey-admin/internal/middleware"
	taskInit "donkey-admin/utility/systask"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {

			taskInit.SysTaskServiceApp.Initialize(ctx)

			consts.Server = g.Server()

			//不鉴权路由
			consts.Server.Group("/api.v1", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				group.Bind(
					login.NewV1(),
					healthy.NewV1(),
				)
			})

			consts.Server.Group("/api.v1/auth", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				group.Middleware(middleware.AuthorityHandler)
				group.Middleware(middleware.MiddlewareOperation)
				group.Bind(
					menu.NewV1(),
					operation_log.NewV1(),
					apis.NewV1(),
					role.NewV1(),
					user.NewV1(),
					task.NewV1(),
					taskLog.NewV1(),
				)
			})
			consts.Server.Run()
			return nil
		},
	}
)
